package com.ronx.scs.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.memory.InMemoryDaoImpl;
import org.springframework.stereotype.Service;

import java.util.Properties;


@Service
public class ChangePasswordServiceImpl extends InMemoryDaoImpl implements ChangePasswordService {

    @Override
    public void changePassword(String username, String password) {
        // get the UserDetails
        User userDetails = (User) getUserMap().getUser(username);

        // create a new UserDetails with the new password
        User newUserDetails =
            new User(userDetails.getUsername(), password, userDetails.isEnabled(), userDetails.isAccountNonExpired(), userDetails.isCredentialsNonExpired(),
                userDetails.isAccountNonLocked(), userDetails.getAuthorities());

        // add to the map
        getUserMap().addUser(newUserDetails);
    }

    @Override
    @Autowired
    @Qualifier(value = "properties")
    public void setUserProperties( Properties props) {
        super.setUserProperties(props);
    }
}
